package com.letu.core.dynamic;

import java.util.ArrayList;
import java.util.List;

/**
 * 生成
 */
public class FieldTypeUtil {

    public static List<Class> voBusinClass = new ArrayList<>();

    /**
     * obj 返回数据类型
     *
     * @param obj
     * @return
     */
    public static Class getClassByFidldType(Class obj) {
        Class c = getClassByJavaGenericity(obj);
        if (c == null) {
            return getClassByBusinList(obj);
        }
        return c;
    }

    public static void addVoBusinClass(Class class2) {
        if (class2 != null) {
            voBusinClass.add(class2);
        }

    }

    public static List<Class> getBuinClass() {
        return voBusinClass;
    }

    public static Class getClassByBusinList(Class obj) {
        for (Class c : getBuinClass()) {
            if (c.getName().equals(obj.getName())) {
                return c;
            }
        }
        return null;
    }

    public static Class getClassByJavaGenericity(Class obj) {
        FieldType fieldType = FieldType.findByField(obj.getName());
        if (fieldType == null) {
            return null;
        }
        return fieldType.getTargerClazz();
    }
}
